//
//  Qiye_Detail.m
//  HappyStore
//
//  Created by 点点充 on 16/1/27.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "Qiye_Detail.h"

@interface Qiye_Detail ()<UICollectionViewDataSource,UICollectionViewDelegate,UITextViewDelegate>
{
    UICollectionView *mainCollection;
    
    UITextView *mainTV;
    UIImage *imgUserHeaderImg;//用户头像
    UIButton *btnHeader;
    UIButton *btnUserName;//用户名称
    
    NSArray *aryTitle1;
    NSMutableArray *muAryTitleContent;
    
    NSMutableDictionary *dicNoti;
    NSMutableArray *muArySaveImg;
    
    BOOL selectedHeader;
}

@end

@implementation Qiye_Detail

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    self.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBarHidden = NO;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    NSMutableString *muStr = [NSMutableString string];
    BOOL isNull = NO;
    if (_dicInfo[@"companyAccount"] == [NSNull null] || [_dicInfo[@"companyAccount"] isEqualToString:@"null"]) {
        if (_dicInfo[@"companyUserName"] == [NSNull null] || [_dicInfo[@"companyUserName"] isEqualToString:@"null"] ) {
            isNull = YES;
        }
        
    }else {
        if (_dicInfo[@"companyUserName"] == [NSNull null] || [_dicInfo[@"companyUserName"] isEqualToString:@"null"]) {
            [muStr appendFormat:@"%@",_dicInfo[@"companyAccount"]];
        }else {
            [muStr appendFormat:@"%@",_dicInfo[@"companyUserName"]];
        }
        
    }
    
    
    if (_dicInfo[@"goveAccount"] == [NSNull null] || [_dicInfo[@"goveAccount"] isEqualToString:@"null"]) {
        if (_dicInfo[@"goveUserName"] == [NSNull null] || [_dicInfo[@"goveUserName"] isEqualToString:@"null"]) {
            if (isNull) {
                [muStr appendString:@"无"];
            }
            
        }
    }else {
        if (_dicInfo[@"goveUserName"] == [NSNull null] || [_dicInfo[@"goveUserName"] isEqualToString:@"null"]) {
            [muStr appendFormat:@"%@",_dicInfo[@"goveAccount"]];
        }else {
            [muStr appendFormat:@"%@",_dicInfo[@"goveUserName"]];
        }
        
    }
    
    aryTitle1 = @[@"隶属组织:",@"联系方式:",@"所在地区:"];
    muAryTitleContent = [NSMutableArray arrayWithObjects:muStr,_dicInfo[@"mobile"],_dicInfo[@"address"], nil];
    NSArray *aryPhotos = _dicInfo[@"photoalbum"];
    if (aryPhotos.count == 0) {
        muArySaveImg = [NSMutableArray arrayWithObject:[UIImage imageNamed:@"re_project_add2"]];
    }else {
        muArySaveImg = [NSMutableArray arrayWithArray:aryPhotos];
        [muArySaveImg addObject:[UIImage imageNamed:@"re_project_add2"]];
    }
    
    //开启侧滑
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    
}


#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 6;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return 166;
    }else if (indexPath.row <4) {
        return 44;
    }else if (indexPath.row == 4) {//简介
        return 200;
    }else {//相册
        return 150;
    }
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellHeader = @"cellHeader";
    static NSString *cellInfo = @"cellInfo";
    static NSString *cellJianJie = @"cellJianJie";
    static NSString *cellPhotos = @"cellPhotos";
    UITableViewCell *cell;
    
    if (indexPath.row == 0) {
        cell = [tableView dequeueReusableCellWithIdentifier:cellHeader forIndexPath:indexPath];
        //头像
        btnHeader = [cell viewWithTag:10];
        btnHeader.layer.masksToBounds = YES;
        btnHeader.layer.cornerRadius = 35;
        [btnHeader setImage:nil forState:UIControlStateNormal];
        [btnHeader sd_setBackgroundImageWithURL:[NSURL URLWithString:_dicInfo[@"headPhoto"]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"btn_my_touxiang"]];
//        [btnHeader sd_setImageWithURL:[NSURL URLWithString:_dicInfo[@"headPhoto"]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"btn_my_touxiang"]];
        [btnHeader addTarget:self action:@selector(btnClickEditHeaderImg) forControlEvents:UIControlEventTouchUpInside];
        
        UIImageView *imgVip = [cell viewWithTag:11];
        if ([_dicInfo[@"vipLevel"] integerValue] == 0) {
            imgVip.image = [UIImage imageNamed:@"img_my_vip2"];
        }else {
            imgVip.image = [UIImage imageNamed:@"img_my_vip1"];
        }
        //名称
        btnUserName = [cell viewWithTag:12];
        if (_dicInfo[@"username"] == [NSNull null] || [_dicInfo[@"username"] isEqualToString:@"null"]) {
            [btnUserName setTitle:_dicInfo[@"account"] forState:UIControlStateNormal];
        }else {
            [btnUserName setTitle:_dicInfo[@"username"] forState:UIControlStateNormal];
        }
        [btnUserName addTarget:self action:@selector(btnClickEditUserName) forControlEvents:UIControlEventTouchUpInside];
        
    }
    
    else if (indexPath.row <4) {
        cell = [tableView dequeueReusableCellWithIdentifier:cellInfo forIndexPath:indexPath];
        UILabel *labTitle = [cell viewWithTag:10];
        labTitle.text = aryTitle1[indexPath.row-1];
        
        UILabel *labContent = [cell viewWithTag:11];
        labContent.text = muAryTitleContent[indexPath.row-1];
        
    }
    
    else if (indexPath.row == 4) {//简介
        cell = [tableView dequeueReusableCellWithIdentifier:cellJianJie forIndexPath:indexPath];
        mainTV = [cell viewWithTag:10];
        mainTV.layer.masksToBounds = YES;
        mainTV.layer.cornerRadius = 5.f;
        mainTV.layer.borderColor = [UIColor colorWithRed:201/255.0f green:202/255.0f blue:202/255.0f alpha:1.0f].CGColor;
        mainTV.layer.borderWidth = 0.5f;
        
        mainTV.delegate = self;
        NSString *strText = _dicInfo[@"introduction"];
        
        if (strText.length == 0) {
            mainTV.text = @"企业简介";
        }else {
            mainTV.text = strText;
        }
        
    }
    
    else {//相册
        cell = [tableView dequeueReusableCellWithIdentifier:cellPhotos forIndexPath:indexPath];
        mainCollection = [cell viewWithTag:10];
        mainCollection.delegate = self;
        mainCollection.dataSource = self;
    }
    
    
        
    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];//取消选中状态
    
    //取消显示后退键文字
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = barButtonItem;
    
    if (indexPath.row == 0) {
        
    }else if (indexPath.row <4) {
        switch (indexPath.row-1) {
            case 0://隶属组织
            {
//                [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setLiShuZuzhi:) name:@"setLiShuZuzhi" object:nil];
                
//                UIViewController *lishu = [self.storyboard instantiateViewControllerWithIdentifier:@"mylishuzuzhi"];
//                [self.navigationController pushViewController:lishu animated:YES];
            }
                break;
            case 1://联系方式
            {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"联系电话" message:nil delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
                alert.alertViewStyle = UIAlertViewStylePlainTextInput;
                UITextField *nameField = [alert textFieldAtIndex:0];
                nameField.placeholder = @"请输入您的联系电话";
                nameField.keyboardType = UIKeyboardTypePhonePad;
                
                [alert showAlertWithCompletionHandler:^(NSInteger buttonIndex) {
                    if(buttonIndex == 1){
                        UITextField *tf=[alert textFieldAtIndex:0];
                        if (tf.text.length > 0) {
                            //token=验证用户&userId=用户id&userName=修改用户名&sex=性别&age=年龄&positionName=职位&shipUserId=上属用户id&shipUserType=上属用户类别&address=地址&mobile=联系电话
                            NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
                            [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
                            [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
                            [muDicParameters setObject:tf.text forKey:@"mobile"];//资源类型
                            
                            [self startEditeUserInfoWithDic:muDicParameters withType:3];
                        }
                    }
                }];
            }
                break;
            case 2://所在地
            {
                SelectedAddress *selectAddress = [SelectedAddress sharedSelectedAddress];
                selectAddress.delegatee = self;
                [selectAddress btnClickAddress];
            }
                break;
        }
    }
    
    
//    strProjectId = _aryInfo[indexPath.row][@"projectId"];
//    
//    [self performSegueWithIdentifier:@"project_detail" sender:self];
    
    
}


#pragma mark - 修改头像
- (void)btnClickEditHeaderImg
{
    selectedHeader = YES;
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"照片选择"
                                                             delegate:self
                                                    cancelButtonTitle:@"取消"
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:@"相机",@"相册", nil];
    actionSheet.tag = 200;
    [actionSheet showInView:self.view];
}

#pragma mark - 选择照片
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    //先设定sourceType为相机，然后判断相机是否可用（ipod）没相机，不可用将sourceType设定为相片库
    UIImagePickerController *pickerImage = [[UIImagePickerController alloc] init];
    pickerImage.delegate = self;
    pickerImage.allowsEditing = YES;//设置可编辑
    switch (buttonIndex) {
        case 0:
        {
            NSLog(@"相机");
            pickerImage.sourceType = UIImagePickerControllerSourceTypeCamera;
            [self presentViewController:pickerImage animated:YES completion:nil];//进入照相界面
        }
            break;
        case 1:
        {
            NSLog(@"相册");
            pickerImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; //图片库
            [self presentViewController:pickerImage animated:YES completion:nil];//进入照相界面
        }
            break;
        case 2:
        {
            NSLog(@"取消");
        }
            break;
    }
    
    
    
}

//点击相册中的图片 货照相机照完后点击use  后触发的方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [picker dismissViewControllerAnimated:YES completion:^{}];
    
    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
    
    if (selectedHeader) {
        imgUserHeaderImg = image;
        [self startEditeHeaderImage];
    }else {
        [self startEditePhotosImage:image];
    }
    
    
}

//点击cancel 调用的方法
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissViewControllerAnimated:YES completion:^{}];
}

#pragma mark - 保存图片至沙盒
- (void) saveImage:(UIImage *)currentImage withName:(NSString *)imageName
{
    NSData *imageData = UIImageJPEGRepresentation(currentImage, 0.1);
    // 获取沙盒目录
    NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
    // 将图片写入文件
    [imageData writeToFile:fullPath atomically:NO];
}


#pragma mark 照片的时间名称
- (NSString*)dateString
{
    NSMutableString*string=[[NSMutableString alloc] init];
    NSDate*dayDate=[NSDate date];
    NSDateFormatter*dayFormatter=[[NSDateFormatter alloc] init];
    [dayFormatter setDateFormat:@"yyyy-MM-dd"];
    NSString *dateStrings= [dayFormatter stringFromDate:dayDate];
    NSArray*dayArray=[dateStrings componentsSeparatedByString:@"-"];
    for (int i=0; i<[dayArray count]; i++) {
        [string appendFormat:@"%@",[dayArray objectAtIndex:i]];
    }
    NSDate*timeDate=[NSDate date];
    NSDateFormatter*timeFormatter=[[NSDateFormatter alloc] init];
    [timeFormatter setDateFormat:@"HH:mm:ss:SSS"];
    NSString *timeString= [timeFormatter stringFromDate:timeDate];
    NSArray*timeArray=[timeString componentsSeparatedByString:@":"];
    for (int i=0; i<[timeArray count]; i++) {
        [string appendFormat:@"%@",[timeArray objectAtIndex:i]];
    }
    return string;
    
}

#pragma mark - 开始上传头像
- (void)startEditeHeaderImage
{
    //token=rE3F2m8AvfC7CVh85O9q&userId=9 参数说明：photo-为图片
    [self showRoundProgressWithTitle:@"请稍后..."];
    NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
    
    NSString *strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"changePhoto_app_myHome.im.lensum"];
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    [manager POST:strURl parameters:muDicParameters constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        NSData *imageData = UIImageJPEGRepresentation(imgUserHeaderImg, 0.5);
        [formData appendPartWithFileData:imageData name:@"photo" fileName:@"photo.jpg" mimeType:@"image/jpeg"];
        
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
//        NSLog(@"%@",dicInfo);

        if ([dicInfo[@"result"] integerValue] == 1) {
            [btnHeader setImage:imgUserHeaderImg forState:UIControlStateNormal];
            [_dicInfo setObject:dicInfo[@"data"][0] forKey:@"headPhoto"];

            [self showRightWithTitle:dicInfo[@"msg"] autoCloseTime:2];
        }else {

            [self showSingleIconBubble:dicInfo[@"msg"]];
        }

    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

        [self showSingleIconBubble:error.localizedDescription];

    }];
    
}


#pragma mark - 用户昵称
- (void)btnClickEditUserName
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"用户昵称" message:nil delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
    alert.alertViewStyle = UIAlertViewStylePlainTextInput;
    UITextField *nameField = [alert textFieldAtIndex:0];
    nameField.placeholder = @"请输入您的昵称";
    
    [alert showAlertWithCompletionHandler:^(NSInteger buttonIndex) {
        if(buttonIndex == 1){
            UITextField *tf=[alert textFieldAtIndex:0];
            if (tf.text.length > 0) {
                //token=验证用户&userId=用户id&userName=修改用户名&sex=性别&age=年龄&positionName=职位&shipUserId=上属用户id&shipUserType=上属用户类别&address=地址&mobile=联系电话
                NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
                [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
                [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
                [muDicParameters setObject:tf.text forKey:@"userName"];//资源类型
                
                [self startEditeUserInfoWithDic:muDicParameters withType:1];
            }
        }
    }];
}

- (void)startEditeUserInfoWithDic:(NSDictionary *)dicc withType:(NSInteger)type
{
    //token=rE3F2m8AvfC7CVh85O9q&userId=用户id&userName=用户名称&introduction=简介&address=地区&mobile=联系电话&shipUserId=上属公司id
    [self showRoundProgressWithTitle:@"请稍后..."];
    
    NSString *strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"updateUser_Company_app_myHome.im.lensum"];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:strURl parameters:dicc progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
//        NSLog(@"%@",dicInfo);

        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
            switch (type) {
                case 1://修改用户名
                {
                    [_dicInfo setObject:dicc[@"userName"] forKey:@"username"];
                    [btnUserName setTitle:dicc[@"userName"] forState:UIControlStateNormal];
                }
                    break;
                case 2://隶属组织
                {
                    NSString *str1 = @"";
                    if (dicNoti[@"username"] == [NSNull null] || [dicNoti[@"username"] isEqualToString:@"null"]) {
                        str1 = dicNoti[@"account"];
                    }else {
                        str1 = dicNoti[@"username"];
                    }
                    [muAryTitleContent replaceObjectAtIndex:0 withObject:str1];
                    [self.mainTableView reloadData];
                }
                    break;
                case 3://联系电话
                {
                    [_dicInfo setObject:dicc[@"mobile"] forKey:@"mobile"];
                    [muAryTitleContent replaceObjectAtIndex:1 withObject:dicc[@"mobile"]];
                    [self.mainTableView reloadData];
                }
                    break;
                case 4://所在地
                {
                    [_dicInfo setObject:dicc[@"address"] forKey:@"address"];
                    [muAryTitleContent replaceObjectAtIndex:2 withObject:dicc[@"address"]];
                    [self.mainTableView reloadData];
                }
                    break;
                default:
                    break;
            }

            [self showRightWithTitle:[dicInfo objectForKey:@"msg"] autoCloseTime:2];
        }else {

            [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];
        }

    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

        [self showSingleIconBubble:error.localizedDescription];

    }];
}


#pragma mark - 设置隶属组织
- (void)setLiShuZuzhi:(NSNotification *)dic
{
    dicNoti = [NSMutableDictionary dictionaryWithDictionary:dic.userInfo];//通过这个获取到传递的对象
    
    //token=rE3F2m8AvfC7CVh85O9q&userId=用户id&userName=用户名称&introduction=简介&address=地区&mobile=联系电话&shipUserId=上属公司id
    NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
    [muDicParameters setObject:dicNoti[@"userId"] forKey:@"shipUserId"];//上属用户id
    
    [self startEditeUserInfoWithDic:muDicParameters withType:2];
}

#pragma mark - 所在地代理
- (void)seceltedRowSshowMsg:(NSString *)showMsg andProvince:(NSString *)strProvince andCity:(NSString *)strCity andDistrict:(NSString *)strDistrict
{
    //token=验证用户&userId=用户id&userName=修改用户名&sex=性别&age=年龄&positionName=职位&shipUserId=上属用户id&shipUserType=上属用户类别&address=地址&mobile=联系电话
    NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
    [muDicParameters setObject:showMsg forKey:@"address"];//资源类型
    
    [self startEditeUserInfoWithDic:muDicParameters withType:4];
}

#pragma mark- UICollectionViewDelegate
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
//个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return muArySaveImg.count;
    
}
//行内容
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *cell1 = @"cell1";
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cell1 forIndexPath:indexPath];
    
    //    NSLog(@"子视图:%@",cell.subviews);
    
    UIButton *btnImage = [cell viewWithTag:10];
    btnImage.layer.masksToBounds = YES;
    btnImage.layer.cornerRadius = 5.f;
    
    [btnImage addTarget:self action:@selector(btnClickAddImage:) forControlEvents:UIControlEventTouchUpInside];
    btnImage.hidden = NO;
    btnImage.userInteractionEnabled = YES;
    
    UIButton *btnDelete = [cell viewWithTag:11];
    btnDelete.hidden = NO;
    [btnDelete addTarget:self action:@selector(btnClickDeleteImage:) forControlEvents:UIControlEventTouchUpInside];
    
    //    NSLog(@"子视图:%@",btnDelete.superview);
    
    if (muArySaveImg.count == 1 || indexPath.row == muArySaveImg.count-1) {
        btnDelete.hidden = YES;
        [btnImage setImage:muArySaveImg[indexPath.row] forState:UIControlStateNormal];
    }else {
        btnImage.userInteractionEnabled = NO;
        [btnImage sd_setImageWithURL:[NSURL URLWithString:muArySaveImg[indexPath.row]] forState:UIControlStateNormal];
    }
    
    if (muArySaveImg.count == 6 && indexPath.row == muArySaveImg.count -1) {
        btnImage.hidden = YES;
        btnDelete.hidden = YES;
    }
    
    
    
    return cell;
}

#pragma mark - 添加5张图片
- (void)btnClickAddImage:(UIButton *)sender
{
    selectedHeader = NO;
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"照片选择"
                                                             delegate:self
                                                    cancelButtonTitle:@"取消"
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:@"相机",@"相册", nil];
    [actionSheet showInView:self.view];
}

#pragma mark - 删除5张图片
- (void)btnClickDeleteImage:(UIButton *)sender
{
    UIView *viewContent = sender.superview;
    
    NSIndexPath *indexPath = [mainCollection indexPathForCell:(UICollectionViewCell *)viewContent.superview];
    NSLog(@"--------%ld",indexPath.row);
    
    
    [self startDeletePhotosImage:indexPath];
    
    
}


- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    if ([textView.text isEqualToString:@"企业简介"]) {
        textView.text = @"";
        textView.textColor = [UIColor colorWithRed:89/255.0f green:87/255.0f blue:87/255.0f alpha:1.0f];
    }
    
    return YES;
}

- (void)textViewDidEndEditing:(UITextView *)textView
{
    if (textView.text.length == 0) {
        textView.text = @"企业简介";
        textView.textColor = [UIColor colorWithWhite:0.75 alpha:1.f];
    }else {
        //token=rE3F2m8AvfC7CVh85O9q&userId=用户id&userName=用户名称&introduction=简介&address=地区&mobile=联系电话&shipUserId=上属公司id
        NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
        [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
        [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
        [muDicParameters setObject:textView.text forKey:@"introduction"];//简介
        
        [self startEditeUserInfoWithDic:muDicParameters withType:5];
    }
    
}


#pragma mark - 开始上传相册照片
- (void)startEditePhotosImage:(UIImage *)imaggs
{
    //token=rE3F2m8AvfC7CVh85O9q&userId=用户id 参数说明：photo-为图片
    [self showRoundProgressWithTitle:@"请稍后..."];
    NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
    
    NSString *strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"addCompanyPhotoalbum_app_myHome.im.lensum"];
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    [manager POST:strURl parameters:muDicParameters constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        NSData *imageData = UIImageJPEGRepresentation(imaggs, 0.5);
        [formData appendPartWithFileData:imageData name:@"photo" fileName:@"photo.jpg" mimeType:@"image/jpeg"];
        
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
//        NSLog(@"%@",dicInfo);

        if ([dicInfo[@"result"] integerValue] == 1) {
            //5张详情 图片
            [muArySaveImg insertObject:dicInfo[@"data"] atIndex:0];
            if (muArySaveImg.count == 2) {
                [muArySaveImg replaceObjectAtIndex:1 withObject:[UIImage imageNamed:@"re_project_add3"]];
            }
            [mainCollection reloadData];

            [self showRightWithTitle:dicInfo[@"msg"] autoCloseTime:2];
        }else {

            [self showSingleIconBubble:dicInfo[@"msg"]];
        }

    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

        [self showSingleIconBubble:error.localizedDescription];

    }];
    
}

#pragma mark - 开始删除相册照片
- (void)startDeletePhotosImage:(NSIndexPath *)indexPath
{
    //token=rE3F2m8AvfC7CVh85O9q&userId=10&photoUrl=图片地址
    [self showRoundProgressWithTitle:@"请稍后..."];
    NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
    [muDicParameters setObject:muArySaveImg[indexPath.row] forKey:@"photoUrl"];//图片地址
    
    NSString *strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"deleteCompanyPhotoalbum_app_myHome.im.lensum"];
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    [manager POST:strURl parameters:muDicParameters constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
//        NSLog(@"%@",dicInfo);

        if ([dicInfo[@"result"] integerValue] == 1) {
            [muArySaveImg removeObjectAtIndex:indexPath.row];
            [mainCollection reloadData];

            [self showRightWithTitle:dicInfo[@"msg"] autoCloseTime:2];
        }else {

            [self showSingleIconBubble:dicInfo[@"msg"]];
        }

    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

        [self showSingleIconBubble:error.localizedDescription];

    }];
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
